{% extends 'layout.html' %}
{% load rbac %}

{% block content %}
    <div class="luffy-container">
        {% if search_list %}
            <div style="float: right;margin: 5px 0;">
                <form method="GET" class="form-inline">
                    <div class="form-group">
                        <input class="form-control" type="text" name="q" value="{{ search_value }}" placeholder="关键字搜索">
                        <button class="btn btn-primary" type="submit">
                            <i class="fa fa-search" aria-hidden="true"></i>
                        </button>
                    </div>
                </form>
            </div>
        {% endif %}

        <form method="post">
            {% csrf_token %}

            {% if action_dict %}
                <div style="float: left;margin: 5px 10px 5px 0;">
                    <div class="form-inline">
                        <div class="form-group">
                            <select class="form-control" name="action">
                                <option value="">请选择操作</option>
                                {% for func_name,func_text in action_dict.items %}
                                    <option value="{{ func_name }}">{{ func_text }}</option>
                                {% endfor %}
                            </select>
                            <input class="btn btn-primary" type="submit" value="执行"/>
                        </div>
                    </div>
                </div>
            {% endif %}

            <div class="btn-group" style="margin: 5px 0">
                {% if request|has_permission:'notice_add' %}
                    <a class="btn btn-primary" href="{% memory_url request 'notice_add' %}">
                        <i class="fa fa-plus-square" aria-hidden="true"></i> 添加消息
                    </a>
                {% endif %}

            </div>

            <table class="table table-bordered table-hover">
                <thead>
                <tr>
                    <th>选择</th>
                    <th>序号</th>
                    <th>标题</th>
                    <th>作者</th>
                    <th>发布时间</th>
                    {% if request|has_permission:'notice_edit' or request|has_permission:'notice_del' %}
                        <th>操作</th>
                    {% endif %}

                </tr>
                </thead>
                <tbody>
                {% for row in notice_queryset %}
                    <tr>
                        <td><input type="checkbox" name="pk" value={{ row.pk }} /></td>
                        <td>{{ row.id }}</td>
                        <td><a href="{% memory_url request 'notice_info' pk=row.id %}">{{ row.title }}</a></td>
                        <td>{{ row.author }}</td>
{#                        <td>{{ row.created_time | date:'Y-m-d-h-i-s' }}</td>#}
                        <td>{{ row.created_time }}</td>

                        {% if request|has_permission:'notice_edit' or request|has_permission:'notice_del' %}
                            <td>
                                {% if request|has_permission:'notice_edit' %}
                                    <a style="color: #333333;" href="{% memory_url request 'notice_edit' pk=row.id %}">
                                        <i class="fa fa-edit" aria-hidden="true"></i></a>
                                {% endif %}
                                {% if request|has_permission:'notice_del' %}
                                    <a style="color: #d9534f;" href="{% memory_url request 'notice_del' pk=row.id %}"><i
                                            class="fa fa-trash-o"></i></a>
                                {% endif %}
                            </td>
                        {% endif %}
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </form>
        <nav>
            <ul class="pagination">
                {{ pager.page_html|safe }}
            </ul>
        </nav>

    </div>
{% endblock %}